package cn.technology.forum.service;

import cn.technology.forum.dto.PaginationDTO;
import cn.technology.forum.dto.QuestionDTO;
import cn.technology.forum.dto.QuestionQueryDTO;
import cn.technology.forum.dto.UserDTO;
import cn.technology.forum.enums.SortEnum;
import cn.technology.forum.exception.CustomizeErrorCode;
import cn.technology.forum.exception.CustomizeException;
import cn.technology.forum.mapper.*;
import cn.technology.forum.model.*;
import cn.technology.forum.util.TimeUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;


@Service
public interface QuestionService {

   PaginationDTO listByQuestionQueryDTO(QuestionQueryDTO questionQueryDTO);


    PaginationDTO listwithColumn(String search, String tag, String sort, Integer page, Integer size, Integer column2,UserAccount userAccount);

    static List<String> getHtmlImageSrcList(String htmlText)
    {
        List<String> imgSrc = new ArrayList<String>();
        Matcher m = Pattern.compile("src=\"?(.*?)(\"|>|\\s+)").matcher(htmlText);
        while(m.find())
        {
            imgSrc.add(m.group(1));
        }
        return imgSrc;
    }

    String getTextDescriptionFromHtml(String html);

    String getShortDescription(String description,Long id);


    PaginationDTO list(String search, String tag, String sort, Integer page, Integer size);

    List<QuestionDTO> listTopwithColumn(String search, String tag, String sort, Integer column2);

    List<QuestionDTO> listTop(String search, String tag, String sort);

    PaginationDTO listByExample(Long userId, Integer page, Integer size, String likes);

    PaginationDTO listByUserId(Long userId, Integer page, Integer size);

    QuestionDTO getById(Long id,Long viewUser_id);

    void createOrUpdate(Question question,UserDTO user);

    void incView(Long id);

    List<QuestionDTO> selectRelated(QuestionDTO queryDTO);

    int delQuestionById(Long user_id, Integer group_id,Long id);

    QuestionDTO setStatuses(QuestionDTO questionDTO,Long viewUser_id);

    Question getQuestionById(Long id);

    int updateQuestion(Question question);


}
